package com.ljx.offer;

/**
 * @author 李捷禧
 * Date: 2023/3/12
 * ClassName: C05
 */

public class C05 {

    /**
     * 很棒，StringBuffer好评
     * @param s
     * @return
     */
    public String replaceSpace(String s) {
        StringBuffer str = new StringBuffer();
        String add = "%20";
        char[] cs = s.toCharArray();
        for (int i = 0; i < cs.length; i++) {
            if (cs[i] == ' '){
                str.append(add);
            }else {
                str.append(cs[i]);
            }
        }
        return str.toString();
    }

    public static void main(String[] args) {
        System.out.println(new C05().replaceSpace("We are happy."));
    }
}
